* ======================================
* --------- Estimation sample ----------
* ======================================
* Creates main estimation sample by linking politicians to voters


	use $dta\PanelVoters.dta, clear
	
	
* Match voters to politicians
* ===========================

	* One-step
	run $prog/prog_match $dta/PanelVoters $dta/PanelPoliticians Fam1 idmatch dist
	run $prog/prog_match $dta/PanelVoters $dta/PanelPoliticians Fam2 idmatch dist
	run $prog/prog_match $dta/PanelVoters $dta/PanelPoliticians Work1 netmatch dist
	run $prog/prog_match $dta/PanelVoters $dta/PanelPoliticians Work2 netmatch dist
	run $prog/prog_match $dta/PanelVoters $dta/PanelPoliticians Imm1 netmatch dist
	run $prog/prog_match $dta/PanelVoters $dta/PanelPoliticians Imm2 netmatch dist
	run $prog/prog_match $dta/PanelVoters $dta/PanelPoliticians Imm3a netmatch rank
	run $prog/prog_match $dta/PanelVoters $dta/PanelPoliticians Imm3b netmatch rank

	* Two-step
	run $prog/prog_match2step $dta/PanelVoters $dta/PanelPoliticians Work1 Fam1 netmatch
	run $prog/prog_match2step $dta/PanelVoters $dta/PanelPoliticians Fam1 Work1 idmatch
	run $prog/prog_match2step $dta/PanelVoters $dta/PanelPoliticians Imm1 Fam1 netmatch
	run $prog/prog_match2step $dta/PanelVoters $dta/PanelPoliticians Fam1 Imm1 idmatch
	
	
* Define samples
* ==============
	
	* Family
	gen Fam1 = 1 // everyone in family network
	gen Fam2 = 1 // everyone in family network

	* Others
	foreach net in Work1 Work2 Imm1 Imm2{
		rename Voter_id idPers
		merge m:1 idPers using $dta/Network`net'.dta, nogen ///
			keepusing(`net'*) keep(master matched)
		rename idPers Voter_id
	}
	

* Save estimation sample
* ======================

	save $dta\EstimationSample.dta, replace	
	